<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<body>
  <table border='1'>
    <tr>
      <td><b>Item</b></td>
      <td><b>Total Score</b></td>
      <td><b>Issue Score</b></td>
      <td><b>Issue Description</b></td>
      <td><b>Notes</b></td>
      <td><b>Justification</b></td>
    </tr>
    {% for item in items %}
    <tr>
      <td rowspan='{{ item.reportable_issues | count }}'>{{ item.account }} / {{ item.region }} / {{item.index}} / {{item.name }}</td>
      <td rowspan='{{ item.reportable_issues | count }}'>Total: {{ item.db_item.score }} Unjustified: {{ item.db_item.unjustified_score }}</td>
      {% for issue in item.reportable_issues %}

        {% if loop.index > 1 %}
        <tr>
        {% endif %}
        {% if issue.justified %}
        <td>{{ issue.score }}</td>
        {% elif issue.score <= 3 and issue.score > 0 %}
        <td bgcolor="#fcf8e3">{{ issue.score }}</td>
        {% elif issue.score > 6 %}
        <td bgcolor="#e4b9b9">{{ issue.score }}</td>
        {% else %}
        <td>{{ issue.score }}</td>
        {% endif %}
        <td>{{ issue.issue|e }}</td>
        <td>{{ issue.notes|e }}</td>
        {% if issue.justified %}
          <td bgcolor="#dff0d8">
            <b>{{ issue.user.name|e }}</b><br/>
            <b>{{ issue.justified_date|e }}</b><br/>
            <p>{{ issue.justification|e }}</p><br/>
          </td>
        {% else %}
          <td>None</td>
        {% endif %}
        </tr>
      {% endfor %}
    </tr>
    {% endfor %}
  </table>
</body>
</html>
